package com.gxan.web.servlet.recruitServlet;

import com.alibaba.fastjson.JSONObject;
import com.gxan.service.RecruitService;
import com.gxan.service.impl.RecruitServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/recruit/resume/delResume")
public class DelResumeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");

        Map resultMap = new HashMap<>();
        try {
            Integer resume_id = Integer.parseInt(req.getParameter("resume_id"));

            RecruitService recruitService = new RecruitServiceImpl();
            int res = recruitService.delResumeById(resume_id);
            if (res>0){
                resultMap.put("code",0);
                resultMap.put("msg","删除成功");

                resp.getWriter().write(JSONObject.toJSONString(resultMap));
            }
        } catch (SQLException e) {
            e.printStackTrace();
            resultMap.put("code",-1);
            resultMap.put("msg","系统开小差了，请联系管理员");
            // 需要将Java对象转换为json字符串对象才能在网络中进行传输
            resp.getWriter().write(JSONObject.toJSONString(resultMap));
        }
        resp.getWriter().flush();
        resp.getWriter().close();
    }
}
